package com.sgb.kjwl.viewmodel.self.carMakers;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.transport.InvoiceRateEntity;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

/**
 * Describe:
 * Author:
 * Date:    2021/5/24
 */
public class EditMoreInfoViewModel extends AndroidViewModel {
    //付款方式
    public MutableLiveData<List<GoodsInfoTypeEntity3>> ldPayType = new MutableLiveData<>();
    //发票
    public MutableLiveData<List<InvoiceRateEntity>> ldInvoiceRateEntity = new MutableLiveData<>();
    //是否可议价
    public MutableLiveData<List<GoodsInfoTypeEntity3>> ldBargain = new MutableLiveData<>();

    public EditMoreInfoViewModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 付款方式
     */
    public void getPayType() {
        List<GoodsInfoTypeEntity3> list = new ArrayList<>();
        list.add(new GoodsInfoTypeEntity3("0", "款到发货"));
        list.add(new GoodsInfoTypeEntity3("1", "货到付款"));
        ldPayType.postValue(list);
    }

    /**
     * 可否议价
     */
    public void getBargain() {
        List<GoodsInfoTypeEntity3> list = new ArrayList<>();
        list.add(new GoodsInfoTypeEntity3("1", "可议价"));
        list.add(new GoodsInfoTypeEntity3("0", "不可议价"));
        ldBargain.postValue(list);
    }

    /**
     * 获取发票列表信息
     */
    public void getInvoices() {
        NewAPIManager.getInstance().getLogisticsAPI().getInvoiceListInfo().enqueue(new ICallBack<BaseEntity<List<InvoiceRateEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<InvoiceRateEntity>> data) {
                ldInvoiceRateEntity.postValue(data.getData());
            }

            @Override
            public void onFailure(Call<BaseEntity<List<InvoiceRateEntity>>> call, Throwable t) {
                super.onFailure(call, t);
                ldInvoiceRateEntity.postValue(null);
            }
        });
    }
}
